<?php

/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-05 17:40:26 +0200 (Sat, 05 Jul 2008) $
 * $Rev: 1268 $
 * $Author: gavinspearhead $
 * $Id: index.php 1268 2008-07-05 15:40:26Z gavinspearhead $
 */


define('ORIGINAL_PAGE', $_SERVER['PHP_SELF']);
$path_idx_std = realpath(dirname(__FILE__));
$process_name = 'urd_web'; // needed for message format in syslog and logging 

require_once "$path_idx_std/../functions/defines.php";
require_once "$path_idx_std/../config.php";
require_once "$path_idx_std/../functions/urdversion.php";

if (isset($config['urdweb_logfile']))
	$config['log_file'] = $config['urdweb_logfile'];
else 
	$config['log_file'] = '/dev/null';

require_once "$path_idx_std/../functions/functions.php";
require_once "$path_idx_std/../functions/urd_log.php";

// initialise some stuff
try {
	$db = connect_db();  // initialise the database
} catch (exception $e) {
	echo "Connection to database failed.\n";
	die;
}


require_once "$path_idx_std/../functions/checkauth.php";
$prefs = load_prefs_clean($db, $userID); // load the prefs

// first include all the php files that only define stuff
require_once "$path_idx_std/../functions/exception.php";
require_once "$path_idx_std/../functions/autoincludes.php";
require_once "$path_idx_std/fatal_error.php";

require_once "$path_idx_std/../functions/web_functions.php";
// then execute code we always need
require_once "$path_idx_std/../functions/fix_magic.php";
$index_page = get_pref($db, 'index_page', $userID);
if ($index_page == '' || !file_exists("$index_page.php")) 
	$index_page = get_pref($db, 'index_page_root', 0);
if ($index_page == '' || !file_exists("$index_page.php"))
	header ('location: browse.php');
else
	header("Location: $index_page.php");

?>
